package pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.simpleGraph;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.Graph;
import pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.GraphException;
import pl.edu.agh.gronoMining.frequentSubgraphFinder.graph.Node;

public class SimpleGraph implements Graph {

	
	private Map<Integer, Node> nodesMap = new HashMap<Integer, Node>();
	
	public SimpleGraph() {
		
	}
	
	public void addNode(Node node) throws GraphException {
		if (nodesMap.get(node.getId()) != null)
			throw new GraphException("more than one node with same id");
		nodesMap.put(new Integer(node.getId()), node);
	}
	
	public void removeNode(Node node) throws GraphException {
		nodesMap.remove(node.getId());
	}
	
	public Node getNodeById(int nodeId) {
		return nodesMap.get(new Integer(nodeId));
	}
	
	public Set<Node> getAllNodes() {
		Set<Node> nodesSet = new HashSet<Node>();
		for (Integer nodeId : nodesMap.keySet()) {
			nodesSet.add(nodesMap.get(nodeId));
		}
		return nodesSet;
	}
}

